package cn.javabb.core.service.pay;

import cn.javabb.common.utils.ListUtils;
import cn.javabb.core.base.BaseService;
import cn.javabb.core.entity.pay.GoodsDO;
import cn.javabb.core.mapper.pay.GoodsMapper;
import cn.javabb.core.model.StatusEnum;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Author javabb
 * @Date 2019/8/11 0011 下午 4:42
 * @Desc
 */
@Service
public class GoodsService extends BaseService<GoodsDO> {

    @Autowired
    private GoodsMapper goodsMapper;

    public List<GoodsDO> list(){
        GoodsDO g = new GoodsDO();
        g.setState(StatusEnum.NORMAL.getCode());
        List<GoodsDO> list = this.queryListByWhere(g);
        return list;
    }
    /**
     * 查询分页
     * @param page
     * @param size
     * @param goods
     * @return
     */
    public Page getPage(String page, String size, GoodsDO goods) {
        return this.queryPageByWhere(page,size,goods);
    }

    /**
     * 更新状态
     * @param ids
     * @param state
     * @return
     */
    public boolean updateState(String ids, Integer state) {
        //GoodsDO goods = new GoodsDO().setGoodsId(id).setState(state);
        List<String> idList = ListUtils.stringToListString(ids);
        Example ex = new Example(GoodsDO.class);
        ex.createCriteria().andIn("goodsId", idList);
        GoodsDO goods = new GoodsDO();
        goods.setState(state);
        return this.goodsMapper.updateByExampleSelective(goods, ex)>0?true:false;
    }
    /**
     * 更新状态
     * @param ids
     * @param hot
     * @return
     */
    public boolean updateHot(String ids, Integer hot) {
        List<String> idList = ListUtils.stringToListString(ids);
        Example ex = new Example(GoodsDO.class);
        ex.createCriteria().andIn("goodsId", idList);
        GoodsDO goods = new GoodsDO();
        goods.setHot(hot);
        return this.goodsMapper.updateByExampleSelective(goods, ex)>0?true:false;
    }
}
